package com.example.demo.Controller;

import com.alibaba.fastjson.JSON;
import com.example.demo.Bean.People;
import com.example.demo.Service.LeavePeopleService;
import com.example.demo.Service.LogDateService;
import com.example.demo.Service.PeopleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import com.alibaba.fastjson.JSONObject;


@RestController
@RequestMapping("/people")
public class Controller_1 {
    @Autowired
    private PeopleService peopleService;
    @Autowired
    private LogDateService logDateService;
    @Autowired
    private LeavePeopleService leavePeopleService;

    @RequestMapping("/selectPeople")
    public String selectPeople(){
        return JSON.toJSONString(peopleService.selectPeople());
    }

    @RequestMapping(value = "/updatePeople",method = RequestMethod.POST)
    @ResponseBody
    public void updatePeople(HttpServletRequest request){
        JSONObject people = JSONObject.parseObject(request.getParameter("people"));
        People p = JSONObject.toJavaObject(people,People.class);
        peopleService.updateOnePeople(p);
    }

    @RequestMapping("/selectLogDate")
    public String selectLogDate(){return JSON.toJSONString(logDateService.selectLogDate());}

    @RequestMapping("/selectLeavePeople")
    public String selectLeavePeople(){return JSON.toJSONString(leavePeopleService.selectLeavePeople());}

    @RequestMapping("/deleteOnePeople")
    @ResponseBody
    public void deleteOnePeople(HttpServletRequest request){
        String peopleID = request.getParameter("peopleID");
        peopleService.deleteOnePeople(peopleID);
    }

    @RequestMapping("/comeBack")
    @ResponseBody
    public void comeBack(HttpServletRequest request){
        String peopleID = request.getParameter("peopleID");
        leavePeopleService.comeBack(peopleID);
    }
}
